package cms.bean.forumCode;

import lombok.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ForumCodeReference implements Serializable {
    /**
     * 版块引用代码
     */
    String referenceCode;
    /**
     * 模板路径
     */
    String forumPath;

    /**
     * 将字符串解析成对象
     * @param value
     * @return
     */
    public static ForumCodeReference builder(String value) {
        String[] codeReferences = StringUtils.split(value,"|");//按|号分割
        if(ArrayUtils.isNotEmpty(codeReferences) || codeReferences.length==2){
            return new ForumCodeReference(codeReferences[0],codeReferences[1]);
        }
        return null;
    }

    /**
     * 按|号分割
     * @return
     */
    @Override
    public String toString() {
        return  referenceCode + '|' + forumPath;
    }
}
